﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_BOX_LOCK_LOCK_NUM_H__
#define __XOS_BOX_LOCK_LOCK_NUM_H__

#include "../tools/head.h"

namespace xos
{
    class i_lock;
}

namespace xos_box
{
    // 
    // lock num
    // 
    class lock_num : public xos_stl::mem_item< xos::release_impl< lock_num >, thread_lock >,
        public xos_box::i_lock_num
    {
    public:
        typedef xos::release_impl< lock_num > T;

    public:
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //

        static int get_addr( POOL *** pppPool, LIST *** pppList );

    public:
        lock_num();
        ~lock_num();

    protected:
        thread_lock m_lock;
        int m_nNum;

    public:
        int add( int nNum );
        int sub( int nNum );
        int set( int nNum );
        int get();

    protected:
        int init_data();

    public:
        int init();
        int term();

    public:
    };
}

#endif // __XOS_BOX_LOCK_LOCK_NUM_H__
